import React,{useState,useEffect} from 'react'
import { useParams } from 'react-router';
import './Add.css';

//修改作者信息页面
const Udauthor = () => {
    const arr = ['作者id: ','作者姓名: '];
    const [author,setAuthor] = useState({});
    const {aId} = useParams();
    console.log(aId)
    useEffect(() => {
        fetch("https://api.52h5.xyz:3001/oneauthor?aId="+aId)
        .then(res=>res.json())
        .then(res=>{
            const{aId,aName,aInformation} = res.data[0];
            const arr1 = [aId,aName,aInformation]
            console.log(res.data[0]);
            setAuthor({'作者信息':aInformation});
            arr.map((item,index)=>setAuthor({...author,[item]:arr1[index]}))
        })
    }, [])
    return (
        <div className="board">
            <div className="info">
                <h3>修改作者信息</h3>
                <form action = "https://api.52h5.xyz:3001/udauthor" method = "post" enctype="multipart/form-data">
                <div className="addList">
                    <ul>
                        {
                            arr.map((item,index)=>{
                                return(
                                    <li style={{width:250}}>
                                        <span>{item}</span>
                                        <input name={item}  value={author[item]} onChange={(e)=>setAuthor({...author,[item]:e.target.value})}></input>
                                    </li>
                                )
                            })
                        }
                    </ul>
                    <li id="content" style={{listStyle:'none'}}>
                        <span>作者信息：</span>
                        <textarea name='作者信息: ' value={author['作者信息']} onChange={(e)=>setAuthor({...author,'作者信息: ':e.target.value})}></textarea>
                        <input type="submit" value="提交"/>
                    </li>
                </div>
                </form>
            </div>
        </div>
    )
}
export default Udauthor